package org.dromara.house.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.house.domain.bo.ParkHousingBo;
import org.dromara.house.domain.entity.ParkFloor;
import org.dromara.house.domain.entity.ParkHousingDetails;
import org.dromara.house.service.ParkHousingDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 房源详情表 前端控制器
 * </p>
 *
 * @author LCH
 * @since 2025-08-26
 */
@RestController
@RequestMapping("/park/housingDetails")
public class ParkHousingDetailsController extends BaseController {

    @Autowired
    private ParkHousingDetailsService service;

    /**
     * 获取房源详情表列表
     */
    @SaCheckPermission("park:housingDetails:list")
    @GetMapping("/list")
    public TableDataInfo<ParkHousingDetails> list(ParkHousingBo bo, PageQuery pageQuery) {
        return service.selectPageList(bo, pageQuery);
    }


    /**
     * id获取详细信息
     */
    @SaCheckPermission("system:housingDetails:query")
    @GetMapping(value = "/{id}")
    public R<ParkHousingDetails> getInfo(@PathVariable Long id) {
        return R.ok(service.selectById(id));
    }

    /**
     * 楼宇id获取对应楼层列表
     */
    @SaCheckPermission("system:housingDetails:query")
    @GetMapping(value = "/getParkFloor")
    public R<List<ParkFloor>> getParkFloor(Long housingId) {
        return R.ok(service.getParkFloor(housingId));
    }

    /* *
     * 新增房源详情表
     */
    @SaCheckPermission("system:housingDetails:add")
    @Log(title = "房源详情表管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody ParkHousingDetails parkHousingDetails) {
        return toAjax(service.insertParkHousingDetails(parkHousingDetails));

    }

    /* *
     * 修改房源详情表
     *
     */
    @SaCheckPermission("system:housingDetails:edit")
    @Log(title = "房源详情表管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public R<Void> edit(@Validated @RequestBody ParkHousingDetails parkHousingDetails) {
        return service.updateParkHousingDetails(parkHousingDetails);
    }


    /**
     * 删除房源详情表
     **/
    @SaCheckPermission("system:housingDetails:remove")
    @Log(title = "房源详情表管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{ids}")
    public R<Void> remove(@PathVariable Long[] ids) {
        return toAjax(service.deleteByIds(ids));
    }

}

